<!-- 钱包 -->
<template>
  <div class="addCurrency">
    <x-header :left-options="{backText: ''}">添加新币种</x-header>
    <div class="searchCurrency" @click="$router.push({ path: '/main/searchCurrency' })">
      <x-icon type="ios-search" size="25"></x-icon>
    </div>
    <div class="currencyList">
      <ul>
        <li v-for="currency in currencyList">
          <img :src="currency.icon" alt="" width="25" height="25">
          <span style="font-size: 14px;">{{currency.name}}</span>
          <div class="switchCurrency">
            <group>
              <x-switch title="" v-model="currency.statu" @on-change="changeCurrency(currency.key,currency.statu)" :disabled="currency.statu"></x-switch>
            </group>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
  import { XHeader, XSwitch, Group } from 'vux'
  import tips from '../../service/tips.js'
  import http from '../../service/http.js'
  export default {
    data() {
      return {
        value: 'false',
        value1: true,
        currencyList: [],
      }
    },
    components: {
      XHeader,
      XSwitch,
      Group
    },
    mounted() {
      this.getCurrency();
    },
    methods: {
      getCurrency() {
        http.get('/coins/coin').then((res) => {
          if (res.status == 200) {
            this.currencyList = res.data.body;
          }
        })
      },
      changeCurrency(name) {
        http.put("/coins/coin", {
          name: name
        }).then((res) => {
          if (res.status == 200) {
            tips.tips("添加成功");
          }
        }).catch((res) => {
          tips.tisp(res.msg)
        })

      }
    }
  }
</script>
<style lang="less">
  body {
    background: #f6f6f6;
  }

  .addCurrency .vux-header {
    background: #fff;
  }

  .addCurrency .weui-cells:before {
    content: " ";
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    height: 1px;
    border-top: none !important;
    color: #D9D9D9;
    -webkit-transform-origin: 0 0;
    transform-origin: 0 0;
    -webkit-transform: scaleY(0.5);
    transform: scaleY(0.5);
  }

  .addCurrency .vux-header .vux-header-title {
    line-height: 40px;
    text-align: center;
    font-size: 18px;
    font-weight: 400;
    color: #000;
  }

  .addCurrency .vux-header .vux-header-left .left-arrow:before {
    content: "";
    position: absolute;
    width: 12px;
    height: 12px;
    border: 1px solid #000;
    border-width: 1px 0 0 1px;
    -webkit-transform: rotate(315deg);
    transform: rotate(315deg);
    top: 8px;
    left: 7px;
  }

  .currencyList {
    margin-top: 10px;
    background: #fff;
  }

  .addCurrency .searchCurrency {
    position: absolute;
    right: 15px;
    top: 13px;
  }

  .currencyList ul li {
    height: 50px;
    line-height: 50px;
    border: 1px solid #f6f6f6;
    padding: 0px 15px;
    position: relative;
    img,
    span {
      vertical-align: middle;
    }
  }

  .addCurrency .switchCurrency {
    position: absolute;
    right: 0px;
    top: -17px;
  }

  .addCurrency .weui-cells {
    margin-top: 1.17647059em;
    background-color: #FFFFFF;
    font-size: 17px;
    overflow: hidden;
    position: relative;
    height: 49px;
  }
  
</style>